
/**
 * Creates and registers the feed view of the dashboard
 * 
 * @param string feed_name
 * @param function callback
 */
App.register('ActivityFeed', ActivityFeedView = {
    
    init: function() {
        this.setup();
    },
    
    setup: function() {
        var self = this;

        $('.profile_link').click(function(e) {
            e.preventDefault();
        });

        $(".approve_btn").click(function() {
            var btn = $(this);
            btn.attr("disabled", true);

            var action = $(this).data('action');

            self.approve({
                member_id: $(this).data("member-id"),
                action: $(this).data('action'),
                success: function(msg) {
                    if (action == "decline") {
                        btn.parents("li.list-group-item").hide('slow');
                    }

                    else {
                        btn.parents("small").html(msg);
                    }
                },
                error: function() {
                    btn.removeAttr('disabled');
                }
            });
        });
    },
    approve: function(params) {
        var url = $("#join_approval_url").val();
        var query = {member_id: params['member_id'], action: params['action']};

        $.ajax({
            url: url,
            data: query,
            dataType: 'json',
            type: 'post',
            success: function(res) {
                if (params['success']) {
                    params['success'](res.message);
                }
            },
            error: function(xhr) {
                console.log(xhr.responseText);
                if (params['error']) {
                    params['error']();
                }
            }
        });
    }
});

